<?php
class CategoryTable extends Doctrine_Table
{
    public function createSelect($required = true, $multiple = false)
    {
        $pairs = $this->fetchPairs('id', 'name');
        $select = new Zend_Form_Element_Select('category_id', array('multiple' => $multiple));
        $select
            ->setRequired($required)
            ->addMultioption('0', '---Select category---')
            ->addMultiOptions($pairs)
            ->setLabel('Category');
        return $select;
    }

    public function fetchPairs($key = 'id', $name = 'name')
    {
    	$pairs = array();

    	$categories = Doctrine::getTable('Category')->getTree()->fetchTree();
    	foreach($categories as $category)
            $pairs[$category[$key]] = str_repeat('--', $category['level']).$category[$name] ;

        return $pairs;
    }
}
?>